<!--
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-02 12:03:17
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-02 12:05:52
 * @FilePath: \code\code\JavaScript\ES6-\33-class中的getter和setter.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE   
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //get和set
        class Phone {
            get price() {
                console.log('价格属性被读取');
                return '123';
                //return 返回值给了s.price
            }
            set price(newVal) {
                console.log('价格属性' + newVal + '被修改');
            }
        }

        //实例化对象
        let s = new Phone();
        // console.log(s.price); //价格属性被读取
        //                      123

        s.price = 'abc';
    </script>
</body>

</html>